<?php
	if ($act=='add'){
		if (isset($_FILES['watermark']) && ($_FILES['watermark']['type'] == 'image/x-png')){
			$file = $_FILES['watermark'];
			$file_name1=$_FILES['watermark']['name'];
			$v = $file['tmp_name'];
			if ($v != ""){
				if (isset($setupdata['file_size']) && ($file['size']/1024 > $setupdata['file_size'])) $err->AddError(28);
				else {
					$file_name = "";
					$imagedata = getimagesize($v);
					if (!isset($imagedata['mime'])){
						if ($imagedata[2] == 3) $imagedata['mime'] = 'image/png';
					}
					if ($imagedata === FALSE) $err->AddError(7);
					else {
						if ($imagedata['mime'] == 'image/png') $file_name = uniqid("")."-".$imagedata[0]."x".$imagedata[1].".png";
						else $err->AddError(7);
						if (strlen($file_name) > 3){
							$file_to = $file_name;
							if (strlen($file_name1) <= 0) $file_name1=$_FILES['watermark']['name'];
							if (!(file_exists($setupdata['binary_path']."/watermark"))){
								if ((mkdir($setupdata['binary_path']."/watermark", 0777)) && (copy($file['tmp_name'], $setupdata['binary_path']."/watermark/".$file_to))){
									if (file_exists($setupdata['binary_path']."/watermark/".$file_to)){
										chmod($setupdata['binary_path']."/watermark/".$file_to, 0666);
										$watermarkclass->watermark_add($file, $file_name1, $file_to, $imagedata[0], $imagedata[1], $_SESSION['login_user']);
									}
								}
							} else {
								if (copy($file['tmp_name'], $setupdata['binary_path']."/watermark/".$file_to)){
									if (file_exists($setupdata['binary_path']."/watermark/".$file_to)){
										chmod($setupdata['binary_path']."/watermark/".$file_to, 0666);
										$watermarkclass->watermark_add($file, $file_name1, $file_to, $imagedata[0], $imagedata[1], $_SESSION['login_user']);
									}
								}
							}
						}
					}
				}
			}
		}
	} elseif ($act=='rename') {
		if (isset($_POST["name"]) && isset($_POST["watermark_id"])){
			$watermarkclass->rename_watermark($_POST["watermark_id"], $_POST["name"]);
		}
	} elseif ($act=='mod') {
		if (isset($_POST["watermark_id"]) && isset($_POST["data_x"]) && isset($_POST["data_y"])){
			$watermarkclass->mod_watermark($_POST["watermark_id"], $_POST["data_x"], $_POST["data_y"]);
		}
	} elseif ($act=='del') {
		$watermarkclass->image_del($parent, $field_name, $image_id);
	} elseif ($act=='del_mas') {
		$del_mas = array();
		if (isset($_POST["ids"])) $del_mas=$_POST["ids"];
		if (count($del_mas) > 0){
			$watermarkclass->watermark_del($del_mas);
		}
	}
?>